package org.hmh.offer;

/**
 * Created this one by HMH on 2018/1/20.
 */
public class t26 {

    public static class Solution {
        public int FindGreatestSumOfSubArray(int[] array) {
            if (array == null || array.length < 1) {
                // throw new IllegalArgumentException("Array must contain an element");
                return 0;
            }
            int curSum = 0;
            int max = Integer.MIN_VALUE;
            for (int i : array) {

                if (curSum <= 0) {
                    curSum = i;
                } else {
                    curSum += i;
                }
                if (curSum > max) {
                    max = curSum;
                }

            }
            return max;
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.FindGreatestSumOfSubArray(new int[]{2, -3, 4, 5}));
    }
}
